package com.mcc.system.service.impl;

import java.util.List;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mcc.system.domain.SysOperLog;
import com.mcc.system.mapper.SysOperLogMapper;
import com.mcc.system.service.ISysOperLogService;

/**
 * 操作日志 服务层处理
 *
 * @author gxy
 */
@Service
public class SysOperLogServiceImpl implements ISysOperLogService {

    @Autowired
    private SysOperLogMapper operLogMapper;

    /**
     * 查询系统操作日志集合
     *
     * @param operLog 操作日志对象
     * @return 操作日志集合
     */
    @Override
    public List<SysOperLog> selectOperLogList(SysOperLog operLog) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if (ObjectUtil.isNotEmpty(operLog)) {
            queryWrapper.like(ObjectUtil.isNotEmpty(operLog.getTitle()), "title", operLog.getTitle());
            queryWrapper.eq(ObjectUtil.isNotEmpty(operLog.getBusinessType()), "business_type", operLog.getBusinessType());
            queryWrapper.eq(ObjectUtil.isNotEmpty(operLog.getStatus()), "status", operLog.getStatus());
            queryWrapper.like(ObjectUtil.isNotEmpty(operLog.getOperName()), "oper_name", operLog.getOperName());
            queryWrapper.ge(ObjectUtil.isNotEmpty(operLog.getBeginTime()), "date_format(oper_time,'%Y-%m-%d')", operLog.getBeginTime());
            queryWrapper.le(ObjectUtil.isNotEmpty(operLog.getEndTime()), "date_format(oper_time,'%Y-%m-%d')", operLog.getEndTime());
        }
        queryWrapper.orderByDesc("oper_id");
        return operLogMapper.selectList(queryWrapper);
    }

    /**
     * 新增操作日志
     *
     * @param operLog 操作日志对象
     */
    @Override
    public void insertOperlog(SysOperLog operLog) {
        operLogMapper.insert(operLog);
    }

    /**
     * 批量删除系统操作日志
     *
     * @param operIds 需要删除的操作日志ID
     * @return 结果
     */
    @Override
    public int deleteOperLogByIds(Long[] operIds) {
        if (operIds.length == 0) return 0;
        return operLogMapper.deleteBatchIds(ListUtil.toList(operIds));
    }

    /**
     * 清空操作日志
     */
    @Override
    public void cleanOperLog() {
        operLogMapper.cleanOperLog();
    }
}
